from flask import Blueprint,request,jsonify
from conf.comm import sqlalchemy_context
from database import *
#密码加密
from werkzeug.security import generate_password_hash,check_password_hash
import json 

#蓝图初始化
bp_users = Blueprint('users',__name__)
#注册功能实现
@bp_users.route('/reg',methods=['POST'])

@sqlalchemy_context()
def reg():
    #获取用户输入
    data = json.loads(request.data)
    #有效性验证
    #构造users
    try:
         user = User(username=data['username'],password=generate_password_hash(data['password']),mobile=data['mobile'])
         db.session.add(user)
         db.session.commit()
         return jsonify({"code":200})
    except:
        return jsonify({"code":10010})